<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
        var f = function(){
        }
        typeof f; //'function'
        // f instanceof function; 报错
        f instanceof Function; //true
        f instanceof Object; //true
        f.length; //0
        var add = function(a,b){
            console.log(a + b);
        }
        add.length; //2  length--参数的个数
        //引用（对象）类型（Object（Array、Function、Date等））
        // 数组 日期用instanceof 判断  typeof 返回object（函数返回function）
        // 
        var person = {
            name:"Lily",
            age:20,
            abc: [1,2,3],
            singing:function(){
                console.log("singing");
            },
            playing:function(){
                console.log("playing");
            }
        };
        // 输出方法的属性值和属性值为数组的属性值
        for (var k in person){
            if(typeof person[k] == "function"){
                console.log(person[k]);
            }
            if(person[k] instanceof Array){
                console.log(person[k]);
            }
        }
        // 遍历person对象中所有属性的代码，并在控制台输出除方法外的所有属性的属性值。
        for (var k in person){
            if(typeof person[k] != "function"){
                console.log(person[k]);
            }
            // if(!(person[k] instanceof Function)){
            //     console.log(k);
            // }
        }

        function Student(name, age) {
            this.name = name;
            this.age = age;
        }
        var stu = Student("Lucy", 20);
        //若Student前有new关键字，结果又如何？ object
        console.log(typeof stu); //undefined
        
        //栈内存 
        function f1(){
            console.log(1);
            function f2(){
                console.log(2)
                function f3(){
                    console.log(3);
                }
                f3();
            }
            f2();
        }
        f1();
        // 在sources里面调试 //123
    
        // 通过字面量创建对象
        var obj = {

        }
        // 通过函数创建对象
        var arr = [];
        var arr2 = new Array();
        //Date Object 对象创建 属于对象

        // 通过Object的create方法创建对象
        Object.create;
        //类 静态函数 属于类

        //ppt
        //复制变量
        var a = 20;
        var b = a;
        b = 30;
        console.log(a);//20

        var a = { x: 10, y: 20 };
        var b = a;
        b.x = 5;
        console.log(a.x);//5

        //比较变量
        var a = 20;
        var b = 20;
        console.log(a === b);//?t
        a = b;
        console.log(a === b);//?t

        var a = { x: 10, y: 20 };
        var b = { x: 10, y: 20 };
        console.log(a === b);//? f
        a = b;
        console.log(a === b);//? t

        console.log([] == []); //false
        console.log(2 == 2); //t
        console.log({} == {}); //f

        var num1 = new Number(2);
        var num2 = 2;
        var num3 = new Number(3);
        console.log(num1 == num2); //t
        console.log(num1 === num2); //f
        console.log(num1 == num3); //f
        console.log(num1 === num3); //f

        var a = "2";
        var b = Number(a);
        var c = new Number(a);
        console.log(typeof b) //number
        console.log(typeof c) //object
        console.log(a == b) //t
        console.log(a === b)//f
        console.log(a == c)//t
        console.log(a === c)//f
        
        // 参数传递
        // 例题1
        function foo(num, obj) {
            num = 20;
            obj.value = "hello world";
            //如果改成 obj = {value: "hello world"} 会怎样？
        }
        var num1 = 10;
        var obj1 = {
            value: "hello"
        };
        foo(num1, obj1);
        console.log(num1); //10 值传递 传完之后 互不影响
        console.log(obj1); //hello world 地址传递 传完之后 同一地址 会影响

        // 例题1.1
        //如果改成 obj = {value: "hello world"} 会怎样？
        function foo(num, obj) {
            //传入obj1地址 obj和obj1指向同一地址
            num = 20;
            obj = {value: "hello world"}; 
            //obj与obj1断开 obj指向了其他地址！两者没有关系！
            obj.value = 2222;
            //再改obj的value值也不会影响到obj1。
        }
        var num1 = 10;
        var obj1 = {
            value: "hello"
        };
        foo(num1, obj1);
        console.log(num1); //10
        console.log(obj1); //hello
       
        // 例题2
        var obj1 = {
            value: "111"
        };
        var obj2 = {
            value: "222"
        };

        function change(obj) {
            //obj = {}; //若开启此行代码，输出又会如何，为什么？ 222 111 此时obj指向空对象 obj和obj1无关系
            //obj和obj1 指向同一地址
            obj.value = "333";  
            // obj1.value变成333
            obj = obj2;
            //obj和obj2 指向同一地址
            return obj.value;
            // 即返回obj2 的value值
        }
        var foo = change(obj1);
        console.log(foo); //222
        console.log(obj1.value); //333
        // obj = obj2 与obj.value = "333" 互换位置会怎样？  //333 111

        // 例题2.1
        function change(obj) {
            //obj和obj1 指向同一地址
            obj.value = {};
            obj = obj2;
            //obj和obj2 指向同一地址
            return obj.value;
            // 即返回obj2 的value值
        }
        var foo = change(obj1);
        console.log(foo); //222
        console.log(obj1.value); //{}

        // 例题3
        var a = [1, 2, 3, 4];
        var b = a;
        b.shift(); //删除最后一个
        console.log(a); //[2,3,4]

        // 例题 ??????????????????
        var obj1 = {
            x:2,
            y:{
                z:3
            }
        }
        var obj2 = obj1;
        obj2.y = {
            z:4
        }
        obj2.x = 3;
        console.log(obj1); //{x: 3, y: {z: 4}}
        //obj1与obj2指向同一地址 
        //obj1.x与obj2.x 相同
        //obj1.y与obj2.y 指向同一地址


        var obj3 = {
            x:2,
            y:{
                z:3
            }
        }

        var obj4 = {
            x:2,
            y:{
                z:3
            }
        }
        console.log(obj3 == obj4); //f
        console.log(obj3.x == obj4.x); //t  === t
        console.log(obj3.y == obj4.y); //f === f
        console.log(obj3.y.z == obj4.y.z); //t === t
        
    
    </script>
</body>
</html>